﻿#region Copyright (C) Sector7 Software Studio. All rights reserved
/*******************************************************************************************
 * Creation
 *      Author:         Wolf Lai
 *      Date:           2013/4/7 星期日 21:48:07
 *      Version:        
 * Modification 
 *      Author: 
 *      Date: 
 *      Description: 
 *      Version:
 *******************************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sector7.Framework.DataDictionary.CORS;
using Sector7.Framework.DataDictionary.Utility;
using Sector7.Framework.Core;
using Sector7.Framework.Enums;

namespace Sector7.Framework.DataDictionary.Agents
{
    /// <summary>
    /// 数据模板服务代理
    /// </summary>
    public class DataTemplateServiceAgent
    {
        /// <summary>
        /// 添加数据模板
        /// </summary>
        /// <param name="template">数据模板</param>
        /// <returns>数据模板编号</returns>
        public static int Add(S7_DataTemplate template)
        {
            object templateId = WcfClient.GetInstance().Invoke<object>(
                service => service.AddDataTemplate(template));

            return Convert.ToInt32(templateId);
        }

        public static int AddMetadata(S7_Metadata metadata)
        {
            object metadataId = WcfClient.GetInstance().Invoke<object>(
                service => service.AddMetadata(metadata));

            return Convert.ToInt32(metadataId);
        }

        /// <summary>
        /// 获取所有数据模板
        /// </summary>
        /// <returns>数据模板列表</returns>
        public static List<S7_DataTemplate> GetAll()
        {
            List<S7_DataTemplate> templates = null;

            try
            {
                templates = WcfClient.GetInstance().Invoke<List<S7_DataTemplate>>(
                    service => service.GetAllDataTemplates());
            }
            catch (Exception e)
            {
                Log.WriteLine(LogSeverityType.ERR, "DAD", e);
            }

            return templates;
        }

        /// <summary>
        /// 根据数据模板编号删除当前模板
        /// </summary>
        /// <param name="templateId"></param>
        /// <returns></returns>
        public static int DeleteDataTemplate(int templateId)
        {
            return WcfClient.GetInstance().Invoke<int>(
                service => service.DeleteDataTemplate(templateId));
        }

        /// <summary>
        /// 获取所有数据模板子项未选项
        /// </summary>
        /// <returns></returns>
        public static List<S7_Metadata> GetAllMetadatas()
        {
            return WcfClient.GetInstance().Invoke<List<S7_Metadata>>(
                service => service.GetAllMetadatas());
        }
    }
}
